Imports System.Web.Services
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient

<WebService(Namespace:="http://tempuri.org/")> _
Public Class MyService
    Inherits System.Web.Services.WebService

#Region " Web Services Designer Generated Code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Web Services Designer.
        InitializeComponent()

        'Add your own initialization code after the InitializeComponent() call

    End Sub

    'Required by the Web Services Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Web Services Designer
    'It can be modified using the Web Services Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        'CODEGEN: This procedure is required by the Web Services Designer
        'Do not modify it using the code editor.
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

#End Region
    <WebMethod()> _
        Public Function getResults(ByVal Username As String) As Boolean
        ' Kieåm tra username cuûa khaùch haøng coù toàn taïi trong heä thoáng ?
        Return getResult(Username)
    End Function
    Private Function getResult(ByVal Username As String) As Boolean
        Dim myConn As SqlConnection
        Dim myCmd As SqlCommand
        Dim isOK As Boolean = False
        Try
            Dim strSQL = "select count(*) from tblCustomers "
            strSQL += " where Username = '" & Username
            strSQL += "'"
            Dim myConnection As SqlConnection = _
      New SqlConnection(ConfigurationSettings.AppSettings("cons"))
            myConnection.Open()
            Dim MyCommand = New SqlCommand(strSQL, _
    myConnection)
            Dim a = MyCommand.ExecuteScalar()
            If a > 0 Then
                isOK = True
            Else
                isOK = False
            End If
            myConnection.Close()
        Catch e As Exception
            isOK = False
        End Try
        Return isOK
    End Function
    <WebMethod()> _
    Public Function doIts(ByVal Username As String) As DataSet
        'Returm DataSet
        Return doIt(Username)
    End Function
    Function doIt(ByVal Username As String) As DataSet
        Dim strSQL = "select * from tblCustomers "
        strSQL += " where Username = '"
        strSQL += Username & "'"
        Dim dts As New DataSet()
        Dim sqlConn As New SqlClient.SqlConnection(ConfigurationSettings.AppSettings("cons"))
        Dim sqlDad = _
  New SqlClient.SqlDataAdapter(strSQL, sqlConn)
        Dim sqlCmdBuilder = _
  New SqlClient.SqlCommandBuilder(sqlDad)
        sqlDad.Fill(dts, "tblCustomers")
        Return dts
    End Function


End Class
